package com.example.thirdstage_project.controller;

import com.example.thirdstage_project.common.Code;
import com.example.thirdstage_project.common.Result;
import com.example.thirdstage_project.entity.Usergroup;
import com.example.thirdstage_project.service.UsergroupService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 86158
 * @version 1.0
 * Create by 2022/11/28 21:02
 */



@RestController
@RequestMapping("/usergroups")
public class UserGroupController {
    @Autowired
    private UsergroupService usergroupService;



    /**
     * *查询所有
     */
    @GetMapping
    public Result selectAll() {
        List<Usergroup> list = usergroupService.list();
        Integer code = list != null ? Code.GET_OK : Code.GET_ERR;
        String msg = list != null ? "" : "数据查询失败";
        return new Result(code, list, msg);
    }



    /**
     * 新增数据
     *
     * @param usergroup 实体对象
     * @return 新增结果
     */
    @PostMapping
    public Result insert(@RequestBody Usergroup usergroup) {
        boolean save = usergroupService.save(usergroup);
        return new Result(save ? Code.GET_OK : Code.GET_ERR, save);
    }


}
